package nc.bs.util;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import nc.jdbc.framework.processor.ResultSetProcessor;

public class MapResultSetProcessor implements ResultSetProcessor {
	private static final long serialVersionUID = 2603939816417496305L;

	public Object handleResultSet(ResultSet rs) throws SQLException {
		HashMap results = new HashMap();

		while (rs.next()) {
			ResultSetMetaData metadata = rs.getMetaData();
			int cols = metadata.getColumnCount();
			if (cols != 2) {
				return null;
			}

			String key = rs.getString(1);
			String value = (String) rs.getObject(2);
			results.put(key, value);
		}

		return results;
	}
}